<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: 20971
  Date: 2021/12/30
  Time: 10:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登陆</title>
    <link rel="stylesheet" href="resource/css/bootstrap.css">
    <script type="text/javascript" src="resource/js/jquery-3.2.1.js"></script>
</head>
<body>

<form:form modelAttribute="user" action="login" method="post">
    <table class="table table-hover">
        <tr>
            <td>用户名</td>
            <td>
                <form:input path="username"></form:input>
            </td>
        </tr>
        <tr>
            <td>密码</td>
            <td>
                <form:password path="password"></form:password>
                <span id="sp" style="color: red"></span>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="radio" name="role" value="0">学生
                <input type="radio" name="role" value="1">讲师
                <input type="radio" name="role" value="2">管理员
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" value="登陆" onclick="tolog()">
            </td>
        </tr>
    </table>
</form:form>

<script>
    /*登录*/
    function tolog() {
        $.post("login",$("form").serialize(),function (msg) {
            if(msg.code == 200){
                $("#sp").html("");
                location.href = "list?role="+msg.role;
            }
            if(msg.code == 500){
                alert(msg.msginfo);
                $("#sp").html("✘✘✘")
            }
            if(msg.code == 501){
                $("#sp").html("")
                alert(msg.msginfo);
            }
        })
    }
</script>
</body>
</html>
